#ifndef MAINTOOL_H
#define MAINTOOL_H

#include <QObject>
#include <QVector>
#include <QMap>
#include <QPair>
#include <functional>
#include <atomic>
#include <QHostAddress>
#include <QNetworkConfigurationManager>
#include "mytypes.h"
#include "../ThreadModel/thread_pool.h"

class MainTool : public QObject
{
    Q_OBJECT

public:
    static MainTool* GetInstance(QObject* parent=nullptr);
    static MainTool* GetInstance(int tds,QObject* parent=nullptr);  //指定开辟线程数量
    virtual ~MainTool();

    void RunToolFunction(Yzty::MODECODE toolcode,Yzty::MODECODE mcode,Yzty::MODECODE tcode);   //运行检查模块
    /*
     * toolcode: 调用modelcode
     * mcode:   被调用mcode
     * tcode:   被调用tcode
    */

    void RunToolFunction(Yzty::MODECODE mcode);

    void SetExeCuteToolCode(Yzty::MODECODE tcode,const QVector<QPair<Yzty::MODECODE,Yzty::ITEMCODE>>& codes);   //执行功能前必须设置功能模块

    void StatusBarInforGetLoading();        //加载状态栏信息

private:
    explicit MainTool(QObject *parent = nullptr);
    explicit MainTool(int n=10,QObject *parent = nullptr);
    static MainTool* _instance;

    void NormalCheck(Yzty::MODECODE toolcode,Yzty::NormalToolCode code);
    void SecurityCheck(Yzty::MODECODE toolcode,Yzty::SecurityToolCode code);
    void FileCheck(Yzty::MODECODE toolcode,Yzty::FileToolCode code);
    void DeepCheck(Yzty::MODECODE toolcode,Yzty::DeepToolCode code);
    void VirMachineCheck(Yzty::MODECODE toolcode,Yzty::VirMachineToolCode code);
    void EmailCheck(Yzty::MODECODE toolcode,Yzty::EmailToolCode code);
    void HardCheck(Yzty::MODECODE toolcode,Yzty::HardToolCode code);
    static void checkDir();       //检查缓存目录是否存在，如果不存在，则创建之
signals:
    void Finish(int mcode,int mtcode,int tcode);
    /*
     * mcode: 执行进程码
     * tcode: item码
    */

    void FileFinish(Yzty::MODECODE toolcode,int finish,int total);
    /*
     * total: 文件总个数
     * finish: 完成个数
    */

public slots:

private:
    ThreadPool* pool;

    QVector<QVector<QPair<Yzty::MODECODE,Yzty::ITEMCODE>>>     _modeltools;     //不同检查模块所包含的功能
    /*
     * 不同的功能模块在功能上有交叉
    */
    std::atomic<int> filecnts;
};

#endif // MAINTOOL_H
